package pojo;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;

import org.hibernate.annotations.GenericGenerator;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;

import component.MyJsonSeriallizer;

@Entity
@GenericGenerator(strategy="uuid",name="uuid_merchant")
public class Merchant {
	@Id 
	@GeneratedValue(generator="uuid_merchant")
    private String id;
	@Column(unique=true)
    private String name;
    private String password;
    private String address;
	@JsonSerialize(using=MyJsonSeriallizer.class)
    private String idCardPath;
	@JsonSerialize(using=MyJsonSeriallizer.class)
    private String avatarPath;
    
    @OneToMany(mappedBy="merchant", cascade=CascadeType.PERSIST)
    private List<Food> foodList = new ArrayList<Food>();

    @OneToMany(mappedBy="merchant", cascade=CascadeType.PERSIST)
    private List<Advertisement> advertisementList = new ArrayList<Advertisement>();
    
    @OneToMany(mappedBy="merchant")
    private List<Order> orderList = new ArrayList<Order>();
    
	public Merchant() {
		super();
	}

	public Merchant(String name, String password, String address, String idCardPath, String avatarPath) {
		this.name = name;
		this.password = password;
		this.address = address;
		this.idCardPath = idCardPath;
		this.avatarPath = avatarPath;
	}
	
	public Merchant(String id,String name, String password, String address, String idCardPath, String avatarPath) {
		this.id = id;
		this.name = name;
		this.password = password;
		this.address = address;
		this.idCardPath = idCardPath;
		this.avatarPath = avatarPath;
	}
	
	public Merchant(String id, String name, String password, String address, String idCardPath, String avatarPath,
			List<Food> foodList, List<Advertisement> advertisementList) {
		super();
		this.id = id;
		this.name = name;
		this.password = password;
		this.address = address;
		this.idCardPath = idCardPath;
		this.avatarPath = avatarPath;
		this.foodList = foodList;
		this.advertisementList = advertisementList;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getIdCardPath() {
		return idCardPath;
	}

	public void setIdCardPath(String idCardPath) {
		this.idCardPath = idCardPath;
	}

	public String getAvatarPath() {
		return avatarPath;
	}

	public void setAvatarPath(String avatarPath) {
		this.avatarPath = avatarPath;
	}

	public List<Food> getFoodList() {
		return foodList;
	}

	public void setFoodList(List<Food> foodList) {
		this.foodList = foodList;
	}
	
	public List<Advertisement> getAdvertisementList() {
		return advertisementList;
	}

	public void setAdvertisementList(List<Advertisement> advertisementList) {
		this.advertisementList = advertisementList;
	}

	@Override
	public String toString() {
		return "Merchant{" +
				"id='" + id + '\'' +
				", name='" + name + '\'' +
				", password='" + password + '\'' +
				", address='" + address + '\'' +
				", idCardPath='" + idCardPath + '\'' +
				", avatarPath='" + avatarPath + '\'' +
				'}';
	}
}
